package com.xd.study.utility;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import java.util.List;

/**
 * Created by DGF on 2015/4/28.
 * 使用FragmentPagerAdapter会加载所有的Fragment，不会自动销毁，因此只适用于少量的Fragment。
 * 若要自动销毁，可使用FragmentStatePagerAdapter
 */
public class MyFragmentPagerAdapter extends FragmentPagerAdapter {

    private List<Fragment> fragmentList;

    private List<String> titleList;

    public MyFragmentPagerAdapter(FragmentManager fm, List<Fragment> fragments, List<String> titles) {
        super(fm);
        this.fragmentList = fragments;
        this.titleList = titles;
    }

    @Override
    public Fragment getItem(int i) {
        return this.fragmentList.get(i);
    }


    @Override
    public int getCount() {
        return this.fragmentList.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return this.titleList.get(position);
    }
}
